import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex); //vue的插件机制

//Vuex.Store 构造器选项
const store = new Vuex.Store({
	state: { //存放状态
		isLogin: uni.getStorageSync('isLogin'),
		user: uni.getStorageSync('user'),
		count:uni.getStorageSync('count'),
		sign: uni.getStorageSync('sign'),
	},
	mutations: {
		toLogin(state, val) {
			state.isLogin = val
			uni.setStorageSync('isLogin',val)
		},
		updateUser(state, user) {
			state.user = user
			if (user) {
				uni.setStorageSync('user', user)
			} else {
				// 退出登录 清楚用户相关全部信息
				uni.clearStorageSync()
				// uni.removeStorageSync('user')
			}
		},
		updateCount(state,count){
			state.count=count,
			uni.setStorageSync('count',count)
		},
		updateSign(state,sign){
			state.sign=sign
			uni.setStorageSync('sign',sign)
		}
	}
})
export default store
